package com.baijia.tianxiao.connect.controller;

import java.util.Enumeration;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketSession;

import com.baijia.tianxiao.connect.result.BaseApiResult;
import com.baijia.tianxiao.connect.service.CheckSessionStatusService;
import com.baijia.tianxiao.connect.util.TianxiaoConnectUtil;

@RequestMapping("/connectStatus")
@RestController
public class ConnnectStatusController {

	@Resource
	private CheckSessionStatusService checkSessionStatusService;

	@Resource
	private TianxiaoConnectUtil tianxiaoConnectUtil;
	
	@RequestMapping("/batchCheckStatus")
	public BaseApiResult batchCheck(List<String> sessionKeys) {
		BaseApiResult result = new BaseApiResult();
		
		//异步处理不会等待
		checkSessionStatusService.checkInvalidKeys(sessionKeys);
		
		return result;
	}
	@RequestMapping("/getAllSessionKeys")
	public BaseApiResult getAllSessionKeys(){
		BaseApiResult result = new BaseApiResult();
		Enumeration<String> keys = TianxiaoConnectUtil.getTianxiaoSessionMap().keys();
		result.setDate(keys);	
		return result;
	}
	
	@RequestMapping("/removeSessionKey")
	public BaseApiResult removeSessionKey(String sessionKey,String sessionId,String message){
		BaseApiResult result = new BaseApiResult();
		checkSessionStatusService.removeCloseSession(sessionKey,sessionId,message);
		return result;
	}
}
